from pages.basePage4 import BasePage
from config.setting import host_port
import time

# 元素定位层
class ExaminePage(BasePage):
    def __init__(self):
        BasePage.__init__(self)
        time.sleep(2)
        self.driver.get(f"http://{host_port}/SharedParkingPlace/admin/index.html")

    # 定位物业审核
    def proper_audit(self):
        return self.driver.find_element_by_id('_easyui_tree_6')

    # 定位表单
    def iframe(self):
        return self.driver.find_element_by_id('testIframe')
    # 定位全选
    def check_all(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[2]/div[1]/div/table/tbody/tr/td[1]/div/input')
    # 定位一键审核
    def examine_all(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[1]/span')
    # 定位删除
    def del_ex(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[2]/span')
    # 定位修改
    def modify(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[3]/span')
    # 定位第一行勾选
    def Check(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[2]/div[2]/table/tbody/tr[1]')
    # 定位OK键
    def check_ok(self):
        return self.driver.find_element_by_xpath('//div[@class="dialog-button messager-button"]/a[1]')
    # 定位物业状态
    def property_status(self):
        return self.driver.find_element_by_xpath('//span[@class="textbox-addon textbox-addon-right"]')
    # 定位选择状态
    def select_del(self):
        return self.driver.find_element_by_id('_easyui_combobox_i1_0')
    def review(self):
        return self.driver.find_element_by_id('_easyui_combobox_i1_1')
    def normal(self):
        return self.driver.find_element_by_id('_easyui_combobox_i1_2')
    # 定位物业证书
    def property_certificate(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input2"]')
    # 定位详细介绍
    def detailed_introduction(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input3"]')
    # 定位修改
    def confirm(self):
        return self.driver.find_element_by_xpath('/html/body/div[3]/div[3]/a[2]/span')
    # 定位弹出框
    def popup(self):
        return self.driver.find_element_by_xpath('/html/body/div[6]/div[2]')



class ExamineHandle(ExaminePage):
    #点击物业审核
    def clk_proper_audit(self):
        self.proper_audit().click()

    # 切换表单
    def swith_frame(self):
        a = self.iframe()
        return self.driver.switch_to.frame(a)
    # 点击全选
    def clk_check_all(self):
        self.check_all().click()
    # 点击一键审核
    def clk_examine_all(self):
        self.examine_all().click()
    # 点击确认键
    def clk_check_ok(self):
        self.check_ok().click()
    # 点击删除
    def clk_del(self):
        self.del_ex().click()
    # 点击修改
    def clk_modify(self):
        self.modify().click()
    # 点击物业状态下拉框
    def clk_property_status(self):
        self.property_status().click()
    # 选择删除
    def deleted(self):
        self.del_ex().click()

    # 勾选框选择
    def click_check(self):
        self.Check().click()
    # 选择待审核
    def clk_review(self):
        self.review().click()
    # 选择正常
    def clk_normal(self):
        self.normal().click()
    # 输入物业证书
    def send_property_certificate(self,certificate):
        input2=self.property_certificate()
        input2.clear()
        input2.send_keys(certificate)
    # 输入详细信息
    def send_detailed_introduction(self,content):
        input3=self.detailed_introduction()
        input3.clear()
        input3.send_keys(content)
    # 点击修改
    def clk_confirm(self):
        self.confirm().click()
    # 获取弹出框文本
    def get_text(self):
        result = self.popup().text
        return result

class ExamineBusiness(ExamineHandle):
    def __init__(self):
        ExamineHandle.__init__(self)
    # 一键审核
    def examine_and_verify(self):
        self.clk_proper_audit()
        self.swith_frame()
        self.clk_check_all()
        self.clk_examine_all()
        self.clk_check_ok()
        return self.get_text()
    # 删除
    def del_examine(self):
        self.clk_proper_audit()
        self.swith_frame()
        self.click_check()
        time.sleep(2)
        self.deleted()
        self.clk_check_ok()
        time.sleep(0.5)
        return self.get_text()
    # 修改
    def mondfiy_ex(self,certificate,content):
        self.clk_proper_audit()
        self.swith_frame()
        self.click_check()
        time.sleep(2)
        self.clk_modify()
        self.clk_property_status()
        self.clk_review()
        self.send_property_certificate(certificate)
        self.send_detailed_introduction(content)
        self.clk_confirm()
        time.sleep(2)
        return self.get_text()
if __name__ == '__main__':
    n = ExamineBusiness()
    r = n.del_examine()
    print(r)